package com.ease.integration.ejb2;

import javax.ejb.SessionContext;

import org.apache.commons.lang.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
import org.springframework.ejb.support.AbstractStatelessSessionBean;

/**
 * <!-- it doesn't work when using <value>applicationContext-*.xml</value> --> <bean name="beanFactoryLocatorKey"
 * class="org.springframework.context.support.ClassPathXmlApplicationContext"> <constructor-arg> <list>
 * <value>applicationContext-server-system.xml</value> <value>applicationContext-server-dao.xml</value>
 * <value>applicationContext-server-business-access.xml</value>
 * <value>applicationContext-server-business-inventory.xml</value>
 * <value>applicationContext-server-business-configuration.xml</value>
 * <value>applicationContext-server-business-bulkchange.xml</value>
 * <value>applicationContext-server-integration.xml</value> </list> </constructor-arg> </bean>
 * 
 * @author nathanleewei
 */
public abstract class SpringStatelessSessionBean extends AbstractStatelessSessionBean implements SpringEnterpriseBean {

	/**
	 *
	 */
	private static final long serialVersionUID = -1952246781579033177L;

	// protected void onEjbCreate() throws CreateException {
	// if (logger.isDebugEnabled()) {
	// logger.debug("XXXStatelessSessionBean.onEjbCreate");
	// }
	// BootstrapService bootstrapService = (BootstrapService) getBeanFactory().getBean(BootstrapService.ID);
	// bootstrapService.start(); }

	public void setSessionContext(SessionContext sessionContext) {
		super.setSessionContext(sessionContext);
		setBeanFactoryLocator(ContextSingletonBeanFactoryLocator.getInstance(BEANS_REFERENCE_XML_NAME));
		setBeanFactoryLocatorKey(BEAN_FACTORY_LOCATOR_KEY);
	}

	protected String getBeanDefinitionNames() {
		String[] names = ((ApplicationContext) getBeanFactory()).getBeanDefinitionNames();
		return "\t" + StringUtils.join(names, "\n\t");
	}
}
